package demo0518;

import java.util.Iterator;
import java.util.Set;

public class TestSet {


        public void addEmp(Set<Emp> set, Emp emp) {
            set.add(emp);
        }

        public void findAllEmp(Set<Emp> set) {
            for (Emp emp : set) {
                System.out.println(emp);
            }
        }


        public Emp findEmpName(Set<Emp> set, String empName) {
            for (Emp emp : set) {
                if (empName.equals(emp.getName())) {
                    return emp;
                }
            }
            return null;
        }

        public void deleteEmp(Set<Emp> set, String empNumber) {

            set.removeIf(emp -> empNumber.equals(emp.getNumber()));
        }


        public Emp findEmpNumber(Set<Emp> set, String empNumber) {
            for (Emp emp : set) {
                if (empNumber.equals(emp.getNumber())) {
                    return emp;
                }
            }
            return null;
        }

    public void changeEmpAge(Set<Emp> set, String empNumber, int empAge) {

        Emp foundEmp = findEmpNumber(set, empNumber);

        if (foundEmp != null) {

            set.remove(foundEmp);


            foundEmp.setAge(empAge);
            set.add(foundEmp);

            System.out.println("员工年龄已更新为：" + empAge);
        } else {
            System.out.println("未找到对应员工编号");
        }
    }
}